<template>
  <div class="common-login">
    <el-form-item label="用户名" prop="username">
      <el-input
        class="ps"
        type=""
        v-model="loginForm.username"
        autocomplete="off"
      ></el-input>
    </el-form-item>
    <el-form-item label="密码" prop="password">
      <el-input
        class="ps"
        type="password"
        v-model="loginForm.password"
        autocomplete="off"
      ></el-input>
    </el-form-item>

    <el-form-item label="验证码" prop="captcha">
      <el-input
        maxlength="5"
        v-model.number="loginForm.captcha"
        class="captcha"
        ref="captcha"
        @keydown.native.enter="submitForm('loginForm')"
      ></el-input>
      <span class="captcha-svg">
        <i v-html="captcha"></i>
      </span>
    </el-form-item>

    <el-form-item>
      <el-button type="primary" @click="submitForm('loginForm')"
        >提交</el-button
      >
    </el-form-item>

    <!-- 手机登录按钮 -->
    <el-form-item>
      <div class="sms">
        <svg class="icon" aria-hidden="true">
          <use xlink:href="#icon-ihpone"></use>
        </svg>
        <a
          href="javascript:;"
          @click="isSmsLogin = ture"
          style="color:#fff;font-size:16px"
          >切换短信登录</a
        >
      </div>
    </el-form-item>
  </div>
</template>

<script>
import * as api from "@/api/users.js";
export default {
  mounted() {
    this.getCaptcha();
  },
  data() {
    return {
      isSmsLogin: true,
      captcha: "", //验证码
      loginForm: {
        username: "",
        password: "",
        captcha: ""
      }
    };
  },

  watch: {
    loginForm: {
      handler(newval) {
        console.log(newval);
        this.$emit("syncLoginForm", newval);
      },
      deep: true
    }
  },
  methods: {
    submitForm(formName) {
      console.log(formName);
      this.$emit("submit");
    },
    // 封装获取验证码的方法
    getCaptcha() {
      api.getCaptcha().then(res => {
        this.captcha = res.data.img;
      });
    }
  }
};
</script>

<style scoped lang="less">
.icon-wx {
  width: 25px !important;
  height: 25px !important;
  vertical-align: -7px;
  margin-right: 3px;
}
.login-container {
  text-align: center;
  color: #fff;
  .common-login {
    padding-right: 50px;
  }

  .erwei .img {
    display: inline-block;
    position: relative;
    width: 200px;
    height: 200px;
    img {
      position: absolute;
      left: 0;
    }

    .mask {
      width: 100%;
      height: 100%;
      opacity: 0.8;
      background-color: #fff;
      position: absolute;
      left: 0;
      // background-image: url("../../");
      background-size: 50%;
      background-repeat: no-repeat;
      background-position: center;
      cursor: pointer;
    }
  }

  .jiaobiao {
    font-size: 60px;
    color: #fff;
    position: absolute;
    right: -1px;
    top: -1px;
  }

  .video {
    position: fixed;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
  }

  .el-form {
    border-radius: 4px;
    background-color: rgba(0, 0, 0, 0.3);
    width: 400px;
    position: fixed;
    right: 10%;
    top: 25%;
    padding: 100px 0 50px 0;

    /deep/.el-input__inner {
      width: 250px;
    }
    /deep/.el-button--primary {
      background: blue;
      width: 250px;
    }

    .title {
      margin: 0 0 60px 0;
      text-align: center;
      color: #fff;
    }
  }
}

.smsContainer {
  padding-right: 20px !important;
  width: 89%;
  /deep/ .el-form-item__label {
    margin-left: 80px !important;
    padding: 0 !important;
    padding-right: 10px !important;
  }
  /deep/ .phone {
    width: 140px !important;
  }

  /deep/ .el-form-item__content {
    margin: 0;
  }
}
/deep/ .captcha-svg i svg {
  width: 115px !important;
  position: absolute;
  right: 1px;
  background: #fff;
  cursor: pointer;
  height: 36px;
  border-radius: 0 3px 3px 0;
  top: 3px;
}
</style>
